<?php

declare(strict_types=1);

namespace Plugin\Attractions\AttractionManagement\Repository;

use App\Repository\IRepository;
use Hyperf\Collection\Arr;
use Hyperf\Collection\Collection;
use Hyperf\Database\Model\Builder;
use Plugin\Attractions\AttractionManagement\Model\AttractionUserTouristBooking;

class AttractionUserTouristBookingRepository extends IRepository
{
    public function __construct(protected readonly AttractionUserTouristBooking $model) {}

    public function handleSearch(Builder $query, array $params): Builder
    {
        return $query
            ->when(Arr::get($params, 'bookingId'), static function (Builder $query, $booking_id) {
                $query->where('booking_id', $booking_id);
            })
            ->when(Arr::get($params, 'touristId'), static function (Builder $query, $tourist_id) {
                $query->where('tourist_id', $tourist_id);
            });
    }

    public function list(array $params = []): Collection
    {
        return $this->perQuery($this->getQuery(), $params)
            ->with(['booking:id,user_id,info_id', 'tourist:id,name'])
            ->get(['booking_id', 'tourist_id']);
    }
}